// pages/homepage/homepage.js
var isAtt=true;
const app=getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        ashadow:"10rpx  5rpx 10rpx #FF986C;",
        fshadow:'',
        dsplay1:'block',
        dsplay2:'none',
        show:'none'
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.data.Uid=options.Uid
        this.data.Bid=options.Bid
        this.getRes()
    },
    onShow:function(){
        this.getRes()
    },
    getRes:function(){
        wx.request({
            url: `${app.globalData.url}/me-homepage/`,
            data:{
                Uid:this.data.Uid,
                Bid:this.data.Bid
            },
            success:res=>{
                console.log(res.data);
                let zan=parseInt(res.data[4][0].sums)+parseInt(res.data[5][0].sums);
                zan=zan>9999?parseInt(zan/10000)+'w+':zan;
                let atten=res.data[3][0].counts>9999?parseInt(res.data[3][0].counts/10000)+'w+':res.data[3][0].counts;
                let fan=res.data[2][0].counts>9999?parseInt(res.data[2][0].counts/10000)+'w+':res.data[2][0].counts;
                this.setData({
                    isSta:res.data[1],
                    list:res.data[0],
                    zanSum:zan,
                    attenSum:atten,
                    fanSum:fan
                })
            }
        })
    },
    jumpAtten:function(e){
        wx.navigateTo({
            url:'/pages/me-attenlist/me-attenlist?Uid='+e.currentTarget.dataset.ite.Uid+'&Uname='+e.currentTarget.dataset.ite.Uname
        })
    },
    jumpFan:function(e){
        wx.navigateTo({
            url:'/pages/me-fanlist/me-fanlist?Uid='+e.currentTarget.dataset.ite.Uid+'&Uname='+e.currentTarget.dataset.ite.Uname
        })
    },
    prabtn(){
        this.setData({
            show:'block',
            opa:0.3
        })
    },
    okbtn(){
        this.setData({
            show:'none',
            opa:1
        })
    },
    atbtn:function(e){
        const date=new Date();
        const year=date.getFullYear();
        const month=date.getMonth()+1;
        const day=date.getDate();
        const time=year+'-'+month+'-'+day;
        if(this.data.Bid!=wx.getStorageSync('Uid')){
            wx.request({
                url:`${app.globalData.url}/me-homepage/`,
                method:'POST',
                data:{
                    Time:time,
                    Uid:wx.getStorageSync('Uid'),
                    Bid:this.data.Bid,
                    Astate:e.currentTarget.id=='+关注'?'已关注':'+关注',
                    type:'atten'
                },
                success:res=>{
                    this.getRes();
                }
            })
        }else{
            wx.showModal({
              title:'提示',
              content:'不能关注自己',
              success: function(res){
                if(res.confirm){
                  console.log('点击确定了')
                }else if(res.cancel){
                  console.log('点击取消了')
                  return false;
                }
              }
            })
        }
    },
    workbtn(){
        let that=this;
        that.setData({
            fshadow:'',
            ashadow:'10rpx  5rpx 10rpx #FF986C;',
            dsplay1:'block',
            dsplay2:'none'
        })
        wx.request({
            url: `${app.globalData.url}/me-homepage/`,
            data:{
                Uid:this.data.Uid,
                Bid:this.data.Bid,
                btn:'作品'
            },
            success:res=>{
                console.log(res.data);
                let zan=parseInt(res.data[4][0].sums)+parseInt(res.data[5][0].sums);
                zan=zan>9999?parseInt(zan/10000)+'w+':zan;
                let atten=res.data[3][0].counts>9999?parseInt(res.data[3][0].counts/10000)+'w+':res.data[3][0].counts;
                let fan=res.data[2][0].counts>9999?parseInt(res.data[2][0].counts/10000)+'w+':res.data[2][0].counts;
                that.setData({
                    isSta:res.data[1],
                    list:res.data[0],
                    zanSum:zan,
                    attenSum:atten,
                    fanSum:fan
                })
            }
          })
    },
    fabtn(){
        let that=this;
        that.setData({
            ashadow:'0',
            fshadow:'10rpx  5rpx 10rpx #FF986C;',
            dsplay2:'block',
            dsplay1:'none'
        })
        wx.request({
            url: `${app.globalData.url}/me-homepage/`,
            data:{
                Uid:this.data.Uid,
                Bid:this.data.Bid,
                btn:'喜欢'
            },
            success:res=>{
                console.log(res.data);
                let zan=parseInt(res.data[4][0].sums)+parseInt(res.data[5][0].sums);
                zan=zan>9999?parseInt(zan/10000)+'w+':zan;
                let atten=res.data[3][0].counts>9999?parseInt(res.data[3][0].counts/10000)+'w+':res.data[3][0].counts;
                let fan=res.data[2][0].counts>9999?parseInt(res.data[2][0].counts/10000)+'w+':res.data[2][0].counts;
                that.setData({
                    isSta:res.data[1],
                    list:res.data[6],
                    lists:res.data[0],
                    zanSum:zan,
                    attenSum:atten,
                    fanSum:fan
                })
            }
          })
    },
    changeDetail:function(e){
        let wid=e.currentTarget.id;
        console.log(this.data.Wid);
        wx.navigateTo({
            url:'/pages/com_detail/com_detail?Wid='+wid
        })
    }
})